<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"></meta>
<title>Title</title>
</head>
<body>
	<h1>SSO-Server/login.com</h1>
	<form>
		<label>Username:</label> <input type="text" id="username" />
		<label>Password:</label> <input type="text" id="password" />
		<label>Login:</label> <input type="button" id="submit" />
	</form>
	<h2 id="resp"></h2>
	<div class="attributes" style="display: none;">
		<span id="redirect-url" th:text="${redirectCallbackUrl}"/>
		<span id="client-id" th:text="${clientID}"/>
		<span id="app-site" th:text="${appSite}"/>
	</div>
</body>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
	//<![CDATA[
	function getQueryVariable(variable) {
		var query = window.location.search.substring(1);
		var vars = query.split("&");
		for (var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if (pair[0] == variable) {
				return pair[1];
			}
		}
		return "";
	}
	var redirectCallbackUrl = $("#redirect-url").text()
	var clientID = $("#client-id").text()
	var appSite = $("#app-site").text()
	$("#submit")
			.click(
					function() {
						console.log("onclick")
						$
								.post({
									url : "http://192.168.0.105:8089/oauth/login",
									data : {
										username : $("#username").val(),
										password : $("#password").val()
									},
									success : function(res) {
										if (res.status == "success") {
											$("#resp")
													.text(
															"验证用户名密码正确, 跳转至Authorize页面!");
											setTimeout(
													function() {
														window.location.href = "http://192.168.0.105:8089/oauth/authorize?redirect_url=" + redirectCallbackUrl + "&response_type=code&client_id=" + clientID + "&scope=read&appsite=" + appSite
													}, 1500);
										} else {
											$("#resp")
													.text(
															"Error Username or Password!")
										}
									}
								})
					})
	//]]>
</script>
</html>